package Thread;

public class Demo11 {
    public static void main(String[] args) throws InterruptedException {
        Thread t=new Thread(()->{
            while(!Thread.currentThread().isInterrupted()){
                System.out.println("Hello Thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    // 这个线程掀桌了.
                    // throw new RuntimeException(e);
                    // 1. 加上 break 就是立即终止
                    // 2. 啥都不写 就是不终止
                    // 3. catch 中先执行一些其他逻辑再 break, 就是稍后终止.
                    break;
                }
            }
            System.out.println("Bye Bye Thread");
        });
        t.start();
        System.out.println("12345");
        Thread.sleep(2000);
        t.interrupt();  //终止线程
        System.out.println("Main  "+Thread.currentThread().getName());
    }
}
